package com.dbsop.domain.transport.query;

import com.dbsop.common.enums.FlagConnect;
import org.elasticsearch.index.query.QueryBuilder;
import org.elasticsearch.index.query.QueryBuilders;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.stream.Collectors;

/**
 * IN查询
 */
public class InQuery extends ConditionQuery{

    private List<Object> values = new ArrayList<Object>();

    public InQuery(String columnName) {
        super(columnName);
    }

    @Override
    public QueryBuilder extractBoolQuery() {
        return QueryBuilders.termsQuery(getColumnName(), values.toArray());
    }

    public InQuery(String columnName, List<Object> values) {
        super(columnName);
        this.values = values;
    }

    public InQuery(String columnName, FlagConnect flagConnect, List<Object> values) {
        super(columnName, flagConnect);
        this.values = values;
    }


    public void add(Collection<Object> objs){
        values.addAll(objs);
    }

    public void add(Object ... objs){
        values.addAll(Arrays.stream(objs).collect(Collectors.toList()));
    }

    public List<Object> getValues() {
        return values;
    }

    public void setValues(List<Object> values) {
        this.values = values;
    }
}
